package com.ljc.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 通用响应类
 *
 * @param <T>
 */
@Data
@NoArgsConstructor
public class BaseResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private String code;
    private String msg;
    private T data;

    public BaseResponse(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseResponse(T data) {
        this.data = data;
        msg = "success";
        code = "0";
    }

    public static BaseResponse<String> success() {
        return new BaseResponse<>(null);
    }

    public static BaseResponse<String> success(String data) {
        return new BaseResponse<>(data);
    }

    public static BaseResponse<String> fail() {
        return new BaseResponse<>("1", "fail");
    }

    public static BaseResponse<String> fail(String code, String msg) {
        return new BaseResponse<>(code, msg);
    }
}
